package com.ai.controller.made;

import com.ai.annotation.EnterPathParamLog;
import com.ai.common.CommonResponse;
import com.ai.entity.file.Audio;
import com.ai.entity.file.AudioPage;
import com.ai.entity.made.camera.CameraBO;
import com.ai.model.dto.CoalAudioVo;
import com.ai.service.made.AudioService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * 音频文件管理
 *
 * @Author：xiaosheng
 * @Date：2024/5/15 10:16
 */

@RestController
@RequestMapping("/audio")
public class AudioController {

    @Resource
    AudioService audioService;


    /**
     * 上传音频信息到本地
     * @param file
     * @return
     */
    @PostMapping("/uploadAudio")
    @ApiOperation("音频文件上传并绑定算法功能")
    public CommonResponse uploadAudio(@RequestParam("resources") MultipartFile file, @ModelAttribute CoalAudioVo coalAudioVo) {

        return audioService.uploadAudio(file,coalAudioVo);
    }

    /**
     * 上传音频信息到本地
     *
     * @param file
     * @return
     */
    @PostMapping("/upload")
    @ApiOperation("音频文件上传")
    public CommonResponse insert(@RequestParam("audio") MultipartFile file, @RequestParam("name") String name) {

        return audioService.upload(file,name);
    }


    @PostMapping("/fileList")
    @ApiOperation("查询所有音频信息")
    public CommonResponse fileList(@RequestBody AudioPage audioPage) {

        CommonResponse commonResponse = audioService.selectByPage(audioPage);
        return CommonResponse.ok(commonResponse);
    }

    /**
     * 通过ID查询
     */
    @GetMapping("/oneById/{id}")
    @ApiOperation("通过ID查询")
    public CommonResponse<Audio> oneById(@PathVariable Integer id) {
        Audio resultData = audioService.oneById(id);
        return CommonResponse.ok(resultData);
    }


    /**
     * 修改音频名称
     *
     * @return
     */
    @ApiOperation("修改信息")
    @PostMapping("/modifyInfo")
    public CommonResponse modifyInfo(@RequestBody Audio audio) {

        CommonResponse resultData = audioService.modifyInfo(audio);

        return resultData;
    }


    @ApiOperation("删除音频信息")
    @DeleteMapping("/deleteFile")
    public CommonResponse delete(@RequestBody Audio audio) {
        CommonResponse commonResponse = audioService.delete(audio);
        return commonResponse;
    }


    @PostMapping("/uploadToServer")
    @ApiOperation("上传文件到服务器")
    /**
     * fileId:文件Id
     * server:服务器Id
     */
    public CommonResponse uploadToServer(@RequestParam("fileId") Integer fileId,
                                         @RequestParam("serverId") Integer serverId) {


        return audioService.uploadToServer(fileId, serverId);
    }








}
